﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using ZenHR.AttData.Collection.AttDataRun;
using ZenHR.AttData.Collection.DataEntity;
using ZenHR.AttData.Collection.TaskQueue;
using ZenHR.AttData.Collection.Util;
using ZenHR.AttData.DAL;

namespace ZenHR.AttData.Collection
{
    partial class CollectionService : ServiceBase
    {
        public CollectionService()
        {
            InitializeComponent();
            base.ServiceName = "CollectionService";
        }
     
        CancellationTokenSource cancelTokenSource = new CancellationTokenSource();

        protected override void OnStart(string[] args)
        {
            //TODO:在此处添加代码以启动服务。
            Task.Factory.StartNew(DoWork, cancelTokenSource.Token);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="arg"></param>
        private void DoWork(object arg)
        {
            while (!cancelTokenSource.IsCancellationRequested)  // Worker thread loop
            {
                TaskRun.Run("");
                Thread.Sleep(2000);
            }
        }

        /// <summary>
        /// 
        /// </summary>
        protected override void OnStop()
        {
            //TODO:在此处添加代码以执行停止服务所需的关闭操作。
            cancelTokenSource.Cancel();
            cancelTokenSource.Dispose();
        }
    }
}
